local Util = require("common.Util")
local HeroDefine = require("hero.HeroDefine")
local HeroLogic = require("hero.HeroLogic")
local MoShouExcel = require("excel.moshou")
local RoleDefine = require("role.RoleDefine")
local SkillExcel = require("excel.skill").skill
local BufferExcel = require("excel.buffer").buffer
local Lang = require("common.Lang")
local MoshouLogic = require("moshou.MoshouLogic")

--计算被动技能 加的属性 num 基础值  lv 被动等级 addition 成长系数
function skillAttarsAddition(attrId, num, lv,addition, isFill)
    if num == nil or attrId == nil or addition == 0 or lv == 0 then
        return 0
    end

    local addNum = 0
    if attrId == 101 or attrId == 103 then
        if lv < 30 then
            addNum = num + addition * ( lv - 1) 
        else
            addNum = num + addition * 29.3
        end
    else
        local len = 0
        if lv >= 3 then
            for i = 1, lv do
                local k = (i-1)%3
                if k == 0 then 
                    len = len + 1
                end
            end
        end        
        addNum = num + addition * len
    end       
    addNum = math.floor(addNum)
    if isFill then
        if not RoleDefine.isBasicAttr(attrId) then
            addNum = math.floor(addNum/100)
            addNum = addNum.."%"
        end
    end
    return addNum
end

--魔兽在战斗中给英雄 增加的 属性
local MOSHOU_BEATTR_LIST = {}
function getMoshouBeAttrNew(pet)
    for k in pairs(MOSHOU_BEATTR_LIST) do
        MOSHOU_BEATTR_LIST[k] = nil
    end 
    local petID = pet and pet.id or 0
    if petID == 0 then
        return MOSHOU_BEATTR_LIST
    end

    --魔兽等级属性加成
    local nowLV = pet.lv
    local moshouLvConfig = MoShouExcel.moshouLv[nowLV]
    if moshouLvConfig and #moshouLvConfig.lvAttrs > 0 then
        local lvAttrs = nil
        for i=1,#moshouLvConfig.lvAttrs do
            local key = moshouLvConfig.lvAttrs[i][1]
            local value = moshouLvConfig.lvAttrs[i][2]

            lvAttrs = lvAttrs or {}
            lvAttrs[key] = (lvAttrs[key] or 0) + value
        end

        for k,v in pairs(pet.lvAttrsAdd) do
            lvAttrs = lvAttrs or {}
            lvAttrs[k] = (lvAttrs[k] or 0) + v
        end

        if lvAttrs then
            for k,v in pairs(lvAttrs) do
                MOSHOU_BEATTR_LIST[k] = (MOSHOU_BEATTR_LIST[k] or 0) + v
            end
        end
    end

    --魔兽精练等级属性加成
    local jinglianLV = pet.jinglianLV
    local jingLianConfig = MoShouExcel.moshouJingLian
    if jingLianConfig[jinglianLV] then
        for i=1,jinglianLV do
            local key = jingLianConfig[i].lvAttrs[1]
            local value = jingLianConfig[i].lvAttrs[2]
            MOSHOU_BEATTR_LIST[key] = (MOSHOU_BEATTR_LIST[key] or 0) + value
        end
    end

    --魔兽铸魂属性加成
    local zhuHun = pet.zhuHun or 0
    local zhuHunConfig = MoShouExcel.moshouZhuHun[1]
    if zhuHun > 0 and #zhuHunConfig.zhuHunAttrs > 0 then
        for i=1,#zhuHunConfig.zhuHunAttrs do
            local key = zhuHunConfig.zhuHunAttrs[i][1]
            local value = zhuHunConfig.zhuHunAttrs[i][2] * zhuHun
            MOSHOU_BEATTR_LIST[key] = (MOSHOU_BEATTR_LIST[key] or 0) + value
        end
    end
    
    --魔兽技能等级属性加成
    local skillLV = pet.skillLV
    local putOnMoshou = petID
    local skillAttrConf = MoShouExcel.moshouSkillLvAttrs
    if skillLV > 0 then
        for i=1,#skillAttrConf do
            if putOnMoshou == skillAttrConf[i].moshouID and skillLV >= skillAttrConf[i].skillLV then
                for _,v in ipairs(skillAttrConf[i].lvAttrs) do
                    MOSHOU_BEATTR_LIST[v[1]] = (MOSHOU_BEATTR_LIST[v[1]] or 0) + v[2]
                end
            end
        end
    end

    return MOSHOU_BEATTR_LIST
end

function onFightBegin(human)

end